﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Navigation;

namespace Brianhdk.Utils.VisualStudio.AssemblyInfoDialog
{
    /// <summary>
    /// Interaction logic for AssemblyInformationDialog.xaml
    /// </summary>
    public partial class AssemblyInformationDialog : Window
    {
        ///<summary>
        ///</summary>
        internal AssemblyInformationDialog(IEnumerable<AssemblyInformation> assemblyInformation)
        {
            InitializeComponent();

            DataContext = assemblyInformation;
            Version.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString(2 /* fieldCount */);
        }

        private void HyperlinkRequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            Process.Start(e.Uri.ToString());
        }

        [DllImport("user32.dll")]
        static extern uint GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("user32.dll")]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);

        /// <summary>
        /// Removes Icon from dialog window.
        /// </summary>
        protected override void OnSourceInitialized(EventArgs e)
        {
            IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
            SetWindowLong(hwnd, -16,
                GetWindowLong(hwnd, -16) & (0xFFFFFFFF ^ 0x80000));

            base.OnSourceInitialized(e);
        }
    }
}
